<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>编辑付款记录</title>
    <script type="text/javascript">
      Ext.onReady(function(){
        var payableId = new Ext.form.Hidden({
          name: 'id'
        });
        //首付金额
        var paymentAmount = new Ext.form.NumberField({
          fieldLabel: '付款金额',
          name:"amount",
          allowBlank: true,
          allowDecimals: true,
          allowNegative: false,
          anchor: '90%'
        });

        var actionDate = new Ext.form.DateField({
          fieldLabel: '付款日期',
          name: 'action_date',
          format: 'Y-m-d', //格式化日期
          //disabledDays: [0,6],	//不让选择周六，周日
          //disabledDaysText: "周末要休息",
          invalidText: "您输入的日期格式不对，正确格式为2010-01-18",
          allowBlank: false,
          blankText: "付款日期必须选择",
          emptyText: '付款日期...',
          anchor: '90%'
        });
        
        //付款备注
        var desc = new Ext.form.TextField({
          fieldLabel: '付款备注',
          name: 'description',
          anchor: '95%'
        });

        //提交按钮
        var submitButton = new Ext.Button({
          text: '提交',
          tooltip: '保存并提交采购付款申请。',
          iconCls: 'icon-save',
          handler: function(){
            // check form value
            if (editPayableForm.form.isValid()) {
              editPayableForm.form.submit({
                method: 'GET',
                success: function(result, response){
                  if (response.result.info == "成功") {
                    Ext.MessageBox.show({
                      title: '消息',
                      msg: "更新采购付款申请，操作成功！",
                      buttons: Ext.MessageBox.OK,
                      icon: Ext.MessageBox.INFO
                    });
                    editPayableWin.destroy();
                  }
                  else {
                    Ext.MessageBox.show({
                      title: '消息',
                      msg: response.result.info,
                      buttons: Ext.MessageBox.OK,
                      icon: Ext.MessageBox.WARNING
                    });
                  }
                },
                failure: function(result, response){
                  Ext.MessageBox.show({
                    title: '消息',
                    msg: "通讯失败，请从新操作",
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.MessageBox.WARNING
                  });
                  editPayableWin.destroy();
                }
              });
            }
            else {
              Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
            }
          }
        });
        
        var editPayableForm = new Ext.FormPanel({
          labelWidth: 55, // label settings here cascade unless overridden
          url:'/payables/update',
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            }, {
              name: 'amount'
            }, {
              name: 'action_date',
              type: 'date',
              dateFormat: 'Y/m/d'
            }, {
              name: 'description'
            }]),
          frame:true,
          //title: '添加用户',
          bodyStyle:'padding:5px 5px 0',
          width: 550,
          //height:300,
          items: [{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: .35,
                  layout: 'form',
                  border: false,
                  items: [paymentAmount]
                }, {
                  columnWidth: .35,
                  layout: 'form',
                  border: false,
                  items: [actionDate]
                }]
            },{
              layout: 'column',
              border: false,
              items: [{
                  columnWidth: 1,
                  layout: 'form',
                  border: false,
                  items: [desc]
                }]
            },payableId],
          buttons: [submitButton,{
              text: '取消',
              iconCls: 'exit',
              handler: function(){
                editPayableWin.destroy();
              }
            }]
        });
        //编辑前，把数据引入到表单中。
        // load form and assign value to fields
        editPayableForm.form.load({
          url: '/payables/getPayableById?id=<%=params[:id]%>',
          method : 'GET',
          waitMsg: '正在载入数据...',
          success: function(form, action){
          },
          failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
          }
        });
        editPayableForm.render('edit_payable_form');
      })
    </script>
  </head>
  <body>
    <div id="edit_payable_form"></div>
  </body>
</html>
